package GUitest;

import javax.swing.*;
import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

public class JOptionPaneDemo extends JFrame {
    public static void main(String[] args) {
        new JOptionPaneDemo();
    }

    public JOptionPaneDemo(){
        JButton b1 = new JButton("消息对话框");
        JButton b2 = new JButton("确认对话框");

        b1.addActionListener(new ActionListener() {
            @Override
            public void actionPerformed(ActionEvent e) {
                JOptionPane.showMessageDialog(b1, "提示消息");
                JOptionPane.showMessageDialog(b1, "提示消息", "标题", JOptionPane.INFORMATION_MESSAGE);
                JOptionPane.showMessageDialog(b1, "提示消息", "标题", JOptionPane.ERROR_MESSAGE);
                JOptionPane.showMessageDialog(b1, "提示消息", "标题", JOptionPane.WARNING_MESSAGE);
                JOptionPane.showMessageDialog(b1, "提示消息", "标题", JOptionPane.QUESTION_MESSAGE);
            }
        });

        b2.addActionListener(new ActionListener() {
            @Override
            public void actionPerformed(ActionEvent e) {
                JOptionPane.showMessageDialog(b2, "提示消息");
                JOptionPane.showMessageDialog(b2, "提示消息", "标题", JOptionPane.INFORMATION_MESSAGE);
                JOptionPane.showMessageDialog(b2, "提示消息", "标题", JOptionPane.ERROR_MESSAGE);
                JOptionPane.showMessageDialog(b2, "提示消息", "标题", JOptionPane.WARNING_MESSAGE);
                JOptionPane.showMessageDialog(b2, "提示消息", "标题", JOptionPane.QUESTION_MESSAGE);
            }
        });

        this.setLayout(new FlowLayout());
        this.add(b2);
        this.add(b1);
        this.setTitle("xx");
        this.setVisible(true);
        this.setSize(500, 500);
        this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    }
}
